/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openbookformat.project.newprojectwizard;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.util.NbBundle;

public final class NewOBFProjectVisualPanel1 extends JPanel implements DocumentListener {

    public static final String PROP_PROJECTNAME = "projectName";
    public static final String PROP_PROJECTFOLDER = "projectFolder";
    public static final String PROP_WEBINDEX = "webIndex";
    
    
    /** Creates new form NewOBFProjectVisualPanel1 */
    public NewOBFProjectVisualPanel1() {
        initComponents();
        jProjLocation.setText(System.getProperty("user.dir"));
        jName.getDocument().addDocumentListener(this);
        jProjLocation.getDocument().addDocumentListener(this);
    }

    @Override
    public String getName() {
        return NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.Name");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jName = new javax.swing.JTextField();
        jProjLocation = new javax.swing.JTextField();
        jProjFolder = new javax.swing.JTextField();
        jBrowseBtn = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jWebIndex = new javax.swing.JTextField();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jLabel1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jLabel2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jLabel3.text")); // NOI18N

        jName.setText(org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jName.text")); // NOI18N

        jProjLocation.setText(org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jProjLocation.text")); // NOI18N

        jProjFolder.setEditable(false);
        jProjFolder.setText(org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jProjFolder.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jBrowseBtn, org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jBrowseBtn.text")); // NOI18N
        jBrowseBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBrowseBtnActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jLabel4.text")); // NOI18N

        jWebIndex.setText(org.openide.util.NbBundle.getMessage(NewOBFProjectVisualPanel1.class, "NewOBFProjectVisualPanel1.jWebIndex.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jName, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                                    .addComponent(jProjLocation, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                                    .addComponent(jProjFolder, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jBrowseBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(16, 16, 16))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jWebIndex, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jProjLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBrowseBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jProjFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jWebIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jBrowseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBrowseBtnActionPerformed
        JFileChooser fc = new JFileChooser();
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if((new File(jProjLocation.getText())).exists())
            fc.setSelectedFile(new File(jProjLocation.getText()));
        fc.setDialogTitle("Project folder location ...");
        fc.setVisible(true);
        
        if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            jProjLocation.setText(fc.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_jBrowseBtnActionPerformed

   /**
     * Get the value of webIndex
     *
     * @return the value of webIndex
     */
    public String getWebIndex() {
        return jWebIndex.getText();
    }

    /**
     * Get the value of projectFolder
     *
     * @return the value of projectFolder
     */
    public String getProjectFolder() {
        return jProjFolder.getText();
    }

    /**
     * Get the value of projectName
     *
     * @return the value of projectName
     */
    public String getProjectName() {
        return jName.getText();
    }

    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBrowseBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jName;
    private javax.swing.JTextField jProjFolder;
    private javax.swing.JTextField jProjLocation;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jWebIndex;
    // End of variables declaration//GEN-END:variables

    @Override
    public void insertUpdate(DocumentEvent e) {
        documentChanged(e);
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        documentChanged(e);
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        documentChanged(e);
    }
    
    private void documentChanged(DocumentEvent e) {
        if(e.getDocument() == jName.getDocument()) {
            jProjFolder.setText(jProjLocation.getText() + File.separator + jName.getText());
        } else if(e.getDocument() == jProjLocation.getDocument()) {
            jProjFolder.setText(jProjLocation.getText() + File.separator + jName.getText());
        }
    }
}
